package com.zhss.security.demospringsecurity.service;

import com.zhss.security.demospringsecurity.entity.user.User;
import com.zhss.security.demospringsecurity.mapper.UserMapper;
import com.zhss.security.demospringsecurity.mapper.UserMapper2;
import lombok.AllArgsConstructor;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

/**
 * @ClassName MyUserDetailsService
 * @Description TODO
 * @Author leejiliang
 * @DateTime 2021/9/10 17:29
 * @Version 1.0
 */
@Service
@AllArgsConstructor
public class MyUserDetailsService2 implements UserDetailsService {
	private UserMapper2 userMapper2;

	@Override
	public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
		User user = userMapper2.loadUserByUsername(username);
		if (ObjectUtils.isEmpty(user)) {
			throw new UsernameNotFoundException("未找到用户");
		}else {
			return user;
		}
	}
}
